/**
 * Created by zengy on 2017/6/8.
 */
angular.module('mainApp.userManage',['ui.router'])
    .config(function ($stateProvider) {
        $stateProvider
            .state({
                name:'userManage/userList',
                url:'/userManage/userList',
                templateUrl:'views/userManage/user_list.html?v='+new Date().getMinutes(),
                controller:'userListCtrl'
            })
    })
    .controller('userListCtrl',function ($scope) {
        $scope.$emit('arg',5)
        $scope.userModel={
            pageNo:1,   //查询页数
            pageSize:10 //每页数条数
        }
        $scope.reset=function () {
            $scope.userModel.username="";
            $scope.userModel.cellPhone="";
            $scope.userModel.isVip="";

            $scope.getUserList($scope.userModel.pageNo)
        }
        $scope.pagination = function (currentPage, pageCount) {
            $('.page-function #pagination').remove();
            $('.page-function').html('<ul id="pagination" class="pagination"></ul>');
            $('.pagination').twbsPagination({
                totalPages: pageCount,
                startPage: currentPage,
                visiblePages: 5,
                first: "首页",
                prev: "上一页",
                next: "下一页",
                last: "尾页",
                href: 'javascript:;',
                //hideOnlyOnePage : true,
                onPageClick: function (event, page) {
                    $scope.getUserList(page)
                }
            });
        };
        $scope.getUserList=function (page) {
            if(page){
                $scope.userModel.pageNo=page;
            }
            layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
            new HttpRequest().getUserList($scope.userModel, function (res) {
                layer.closeAll();
                if (res.code == '000') {
                    $scope.userList = res.data.list;
                    $scope.$apply();
                    if ($scope.userList.length > 0) {
                        $scope.pagination($scope.userModel.pageNo, res.data.pageCount);
                    }
                } else {
                    layer.msg(res.msg)
                }
            })
        }

        $scope.getUserList($scope.userModel.pageNo)
        //全选
        // $scope.checkBox=function (event) {
        //    $("input[type='checkbox']").prop('checked',$(event.target).prop('checked'))
        //
        // }

        //通话
        $scope.conversation=function (event) {
            var _this=$(event.target);
            var userId=_this.data('userId');
            var cellPhone=_this.data('tel');
            var username=_this.data('name');
            var index = layer.confirm('与'+username+'联系<br />联系电话'+cellPhone, {
                title: '通话',
                btn: ['确定', '取消'],//按钮
            }, function () {
                layer.closeAll();
               new HttpRequest().customServiceCalling({orderNo:'170612100011',toMobile:cellPhone},function (res) {
                    if(res.code !='000' && res.data !='200'){
                        layer.msg('操作失败！');
                    }
               })
            }, function () {
                layer.close(index)
            })
        }


    })

